import http from '../utils/http';
/**
 * 获取列表
 */
function saveReport(param){
    return new Promise((resolve, reject) => {
        http("post",'/reportWorkbookModel/saveWorkTable',param).then(res => {
              resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function getReportPattern(report_id){
    return new Promise((resolve, reject) => {
        http("get",'/reportWorkbookModel/getWorkTable/'+report_id).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function getReport(report_id){
    let _reportId={reportId:report_id}
    return new Promise((resolve, reject) => {
        http("get",'/reportWorkbookModel/getReport',_reportId).then(res => {
            console.log("=========================================")
            console.log(res)
            console.log("=========================================")
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}


function getReportResult(parameters){
    return new Promise((resolve, reject) => {
        http("post",'/reportWorkbookModel/getReportResult/',parameters).then(res => {
            console.log("=========================================")
            console.log(res)
            console.log("=========================================")
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}




function delReport(report_id){
    return new Promise((resolve, reject) => {
        http("get",'/reportWorkbookModel/delWorkTable/'+report_id).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

//参数为{name:***}
function newReport(param){
    return new Promise((resolve, reject) => {
        http("post",'/reportWorkbookModel/newWorkTable',param).then(res => {
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}


function getReportList(){
    return new Promise((resolve, reject) => {
        http("get",'/reportWorkbook/findAllByTypeid/501').then(res => {
            console.log("ap222-------:"+res);
            resolve (res);
        },error => {
            console.log("网络异常~",error);
            reject(error)
        })
    })
}

function getAccountReportParameter(templateId){
    return new Promise((resolve, reject) => {
        let param={reportTemplateId:templateId}
        http("get",'/reportWorkbookModel/getAccountReportParameter',param).then(res => {
            resolve (res);
            return;
        },error => {
            console.log("login error!~",error);
            reject(error)
        })
    })
}

/***   -------------------开始财务报表---------------------------------**/
function findAccountReports(){
    return new Promise((resolve, reject) => {
        let param={}
        http("get",'/running/find',param).then(res => {
            resolve (res);
            return;
        },error => {
            console.log("login error!~",error);
            reject(error)
        })
    })
}


function duplicateCheck(templateId,AACCOUNT_SET,year,month){
    return new Promise((resolve, reject) => {
        let param={templateId:templateId,aaccountSet:AACCOUNT_SET,year:year,month:month}
        http("get",'/running/duplicateCheck',param).then(res => {
            resolve (res);
            return;
        },error => {
            console.log("login error!~",error);
            reject(error)
        })
    })
}


function removeAccountReport(id){
    return new Promise((resolve, reject) => {
        let p={id:id};
        http("get",'/running/remove',p).then(res => {
            resolve (res);
            return;
        },error => {
            console.log("login error!~",error);
            reject(error)
        })
    })
}





/***   -------------------end财务报表---------------------------------**/

export {
    saveReport,getReportPattern,getReportList,delReport,newReport,
    getReportResult,getAccountReportParameter,findAccountReports,duplicateCheck,removeAccountReport,
    getReport}

